/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Dao;

import pkl53.model.UserModel;
import com.mysql.jdbc.PreparedStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author akhul
 */
public class UserDao {
    
    private Connection connection;
    
    private final String getPasswordByUsername = "SELECT Password FROM mahasiswa WHERE NIM = ?;";
    
//    public void insertUser(UserModel user){
//        
//    }
//
//    public void updateUser(UserModel user){
//        
//    }
//
//    public void deleteUser(String nim){
//        
//    }

    public UserModel getPasswordByUsername(String username){
        UserModel user = null;
        
        PreparedStatement statement;
        ResultSet rs=null;
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/pkl53", "root", "");
            
            conn.setAutoCommit(false);
            statement = (PreparedStatement) conn.prepareStatement(getPasswordByUsername);
                    
            statement.setString(1, username);
            rs = statement.executeQuery();
            user = new UserModel();
            if (rs.next()) {
                
                user.setPassword(rs.getString(1));
            }
            conn.commit();
        
        } catch (SQLException ex) {
            Logger.getLogger(UserDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        return user;
    }
    
    
}
